package com.easy;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 * Created by Lxk on 2019/6/2.
 */
public class Solution349 {

    public int[] intersection(int[] nums1, int[] nums2) {
        Set<Integer> set1 = new HashSet<>();
        for(Integer val : nums1){
            set1.add(val);
        }
        Set<Integer> resSet = new HashSet<>();
        for(Integer val : nums2){
            if(set1.contains(val)){
                resSet.add(val);
            }
        }
        int[] res = new int[resSet.size()];
        Iterator it = resSet.iterator();
        int pos = 0;
        while(it.hasNext()){
            int val = (int) it.next();
            res[pos++] = val;
        }
        return res;
    }

}
